<?php
include 'mysql.php';


if(isset($_SERVER['REQUEST_METHOD'])&&strtolower($_SERVER['REQUEST_METHOD'])=='post')
{

    $param = $_REQUEST['Form'] ;
    $title = $param['title'];
    $name = $param['name'];
    $mobile = $param['mobile'];
    $cid= $param['cid'];
    $desc = $param['desc'];
    $cover = $param['cover'];
    $destination = $param['destination'];
    $address = $param['address'];
    if($_FILES['cover'] )
    {
        $filename = $_FILES['cover']['type'];
        $newname = './upload/'.time().'.jpg';
        if( strtolower( $filename) == 'image/jpeg' )
        {
            if(!move_uploaded_file($_FILES['cover']['tmp_name'] ,$newname) )
            {
                die ('图片上传失败');
            }
            else
            {

              $cover  = $newname ;
            }
        }

    }

    $query = "UPDATE  activity SET `title` = '".$title."',`mobile` = '".$mobile."', `name` = '".$name."', `desc` = '".$desc."', `cover` = '".$cover."', `destination` = '".$destination."', `address` = '".$address."' WHERE `id` = $cid ";

 
    $result=$mysqli->query($query);
    if(!$result)
    {
        echo  "<script>alert('编辑失败')</script>";
    }


}


if(isset($_GET['id'])&&$_GET['id'])
{
     $result = $mysqli->query("select * from activity WHERE id = '".$_GET['id']."'");
     $row = $result->fetch_assoc();

}
?>

    <!doctype html>
    <html>
    <head>
        <title>后台管理</title>
        <meta charset="UTF-8">
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <link href="css/admin_full.css" rel="stylesheet" />
        <script src="js/jquery.js"></script>
        <script type="text/javascript">
        $(function(){

            $('form[name="form_submit"]').submit(function(){

                var title = $('#title').val();
                var name = $('#name').val();
                var mobile = $('#mobile').val();
                var cover = $('#cover').val();
                var desc = $('#desc').val();
                var address = $('#address').val();
                var destination = $('#destination').val();

                if(!title.length){
                    $('#title').focus();
                    return false ;
                }

                if(!name.length){
                    $('#name').focus();
                    return false ;
                }

                if(!mobile.length){
                    $('#mobile').focus();
                    return false ;
                }

                if(!desc.length){
                    $('#desc').focus();
                    return false ;
                }

                if(!address.length){
                    $('#address').focus();
                    return false ;
                }
                if(!destination.length){
                    $('#destination').focus();
                    return false ;
                }

            });
        })

            </script>
    </head>
    <body>

<div id="popup"></div>
<div class="wrap J_check_wrap">
    <div class="h_a">功能说明</div>
    <div class="prompt_text">
编辑活动
</div>
    <div class="h_a">编辑活动</div>
    <div class="search_type cc mb10">
        <form action=" " method="post" name="form_submit" enctype="multipart/form-data">
            <div class="ul_wrap">
                <label>活动标题：</label>
                <input type="text" class="input length_3" name="Form[title]" value="<?php echo @$row['title'];?>" id="title" placeholder="必填">
             </div>
              <div class="ul_wrap">
                <label>发起人：</label>
                <input type="text" class="input length_3" name="Form[name]" value="<?php echo @$row['name'];?>"id="name" placeholder="必填">
             </div>
             <div class="ul_wrap">
                <label>活动封面：</label>
                <img src="<?php echo @$row['cover'];?>" width="120" height="80" >
             </div>

             <div class="ul_wrap">
                <label>修改封面：</label>
                <input type="file" class="input length_3" name="cover" id="cover"  value="<?php echo @$row['cover'];?>" >
             </div>
            <div class="ul_wrap">
                <label>手机号：</label>
                <input type="text" class="input length_3" name="Form[mobile]" value="<?php echo @$row['mobile'];?>" id="mobile"  placeholder="必填">
             </div>
             <div class="ul_wrap">
                <label>活动地点：</label>
                <input type="text" class="input length_3" name="Form[destination]" value="<?php echo @$row['destination'];?>" id="destination"  placeholder="必填">
             </div>
             <div class="ul_wrap">
                <label>活动具体地址：</label>
                <input type="text" class="input length_3" name="Form[address]" value="<?php echo @$row['address'];?>" id="address"  placeholder="必填">
             </div>
            <div class="ul_wrap">
                <label>活动描述：</label>
                <textarea  name="Form[desc]"  placeholder="必填"   id="desc" style="width:300px;"><?php echo @$row['desc'];?></textarea>
             </div>
            <input type="hidden" class="input length_3" name="Form[cid]"   value="<?php echo @$row['id'];?>" >
            <input type="hidden" class="input length_3" name="Form[cover]"   value="<?php echo @$row['cover'];?>" >
             <div class="ul_wrap"> <button class="btn" type="submit">确定</button> </div>
        </form>
    </div>
</div>
</body>
</html>

<?php $mysqli->close(); ?>